package com.liuh.fram.handle;

import com.alibaba.fastjson.JSON;
import com.liuh.fram.err.Error;
import com.liuh.fram.err.LocalException;
import com.liuh.fram.err.LocalException.ErrorType;

/**
 * @note 请求处理
 * @author liuh
 */
public class RequestHandle extends HttpBaseHandle {

	/**
	 * @note 获取响应的协议里的内容数据
	 * @author liuh
	 */
	public String getRepMsg(String jsonContent) {
		String result = "";
		try {
			String code = JSON.parseObject(jsonContent).getString("code");
			if (code.equals("200")) {
				// 响应正确
				result = jsonContent;
			} else {
				// 返回异常包
				Error errorM = JSON.parseObject(jsonContent, Error.class);
				throw new LocalException(errorM);
			}
		} catch (LocalException e) {
			throw e;
		} catch (Exception e) {
			throw new LocalException(ErrorType.parseErr);
		}
		return result;
	}

	/**
	 * 获取响应结果
	 * 
	 * @author liuh
	 * @throws Exception
	 */
	public String requestResult(String result_json) throws Exception {
		result_json = filterJson(result_json);
		return getRepMsg(result_json);
	}
}
